package com.weng.coder.controller;

import com.weng.coder.entity.CoderCondition;
import com.weng.coder.service.ICoderConditionService;
import com.weng.coder.model.vo.CoderConditionVo;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.web.model.request.DeleteReqVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import org.apache.commons.lang3.StringUtils;
import com.weng.framework.web.base.BaseController;
import javax.validation.Valid;
import cn.hutool.core.convert.Convert;


/**
 * 查询条件属性 API实现
 *
 * @author weng
 * @date 2021-04-16 16:08:15
 *
 */  
@Slf4j
@RestController
@RequestMapping("/coder-conditions")
@Api(value = "查询条件属性api", tags = {"查询条件属性操作接口"})
public class CoderConditionController extends BaseController {
    @Autowired
    private ICoderConditionService coderConditionService;

    /**
     * 功能描述:单个获取查询条件属性
     */
    @ApiOperation(value = "获取查询条件属性", notes = "")
    @GetMapping(value = "/{id}")
    public ResponseData get(@PathVariable("id") String id){
        CoderCondition coderCondition = coderConditionService.getById(id);
        return success(coderCondition);
    }


    /**
     * 条件 分页查询查询条件属性
     */
    @ApiOperation(value = "分页获取查询条件属性", notes = "")
    @GetMapping(value = "")
    public ResponseData list(Integer pageNo,Integer pageSize){
		IPage<CoderCondition> iPage = coderConditionService.list(pageNo, pageSize);
        return success(iPage);
    }


    /**
	 * 新增查询条件属性
	 */
	@ApiOperation(value = "新增查询条件属性", notes = "")
	@PostMapping(value = "")
	public ResponseData add(@Valid @RequestBody CoderConditionVo coderConditionReq){
		CoderCondition coderCondition = Convert.convert(CoderCondition.class, coderConditionReq);
		coderConditionService.add(coderCondition);
		return success();
	}

	/**
	 * 更新查询条件属性
	 */
	@ApiOperation(value = "更新查询条件属性", notes = "")
	@PutMapping(value = "")
	public ResponseData update(@Valid @RequestBody CoderConditionVo coderConditionReq){
		CoderCondition coderCondition = Convert.convert(CoderCondition.class, coderConditionReq);
		coderConditionService.update(coderCondition);
		return success();
	}


	/**
	 * 删除查询条件属性
	 */
	@ApiOperation(value = "ids 删除查询条件属性", notes = "可以删除多个，中间以,号分隔")
	@DeleteMapping(value = "")
	public ResponseData delete(@RequestBody DeleteReqVo deleteReq){
		String ids = deleteReq.getIds();
		if(StringUtils.isEmpty(ids)){
			return failed("删除失败,id不能为空！");
		}
		coderConditionService.removeByIds(Arrays.asList(ids.split(",")));
		return success(deleteReq.getIds());
	}
}
